|
|
|
|
|
|
|
programmatically lowers the form's position. Finally, a set of Label controls reports the form's Height, Width, Left, and Top properties. |
|
|
|
|
|
|
|
|
Creating the Form Resize Program |
|
|
|
|
|
|
|
|
When program code refers to properties of various objects, dot notation is used. As an example, the Caption property for a Label control named lblAddress on a particular form is referred to in code as lblAddress.Caption. |
|
|
|
|
|
|
|
|
If you don't remember how to add objects to a form and set the objects' properties, you might want to review Chapter 2. |
|
|
|
|
|
|
|
|
Figure 3.8 shows my completed sample form; you may want to refer to it as you build the project. |
|
|
|
|
|
|
|
|
See "Creating Your Program's User Interface," p. 18 |
|
|
|
|
|
|
|
|
Figure 3.8
This sample project demonstrates the use
of code to set various properties of a form. |
|
|
|
|
|
|
|
|
Perform the following steps to create your own version of this project: |
|
|
|
|
|
|
|
|
1. Create a new Standard EXE project. |
|
|
|
|
|
|
|
|
2. Add four Label controls to the form, aligned in a column at the left side of the form. These labels will be used as captions for other information; you generally don't need to modify the Name properties for labels used in this manner, as they won't be referred to in code. Change the four Label controls' Caption properties to Height, Width, Left, and Top (working from top to bottom). |
|
|
|
|
|
|
|
|
3. Add another column of four Label controls just to the right of the first set. Change their Name properties to lblHeight, lblWidth, lblLeft, and lblTop. Change their Caption properties to nothing (clear out the default captions). |
|
|
|
|
|
|
|
|
4. Add a CommandButton control near the bottom of the form. Change its Name property to cmdWiden, and change its Caption property to Widen Form. |
|
|
|
|
|
|
|
|
5. Select the form and change its Width property to 4000 twips. (See the sidebar "Measurements in Visual Basic" for a definition of the term twip.) |
|
|
|
|
|
|
|
|
6. Double-click the command button to bring up the Code window. You should see an empty cmdWiden_Click sub procedure. |
|
|
|
|
|
|
|
|
7. Press the Tab button, and then type the code Form1.Width = Form1.Width + 100. This line of code causes the value of Form1's Width property to increase by 100 twips each time the command button is clicked. |
|
|
|
|
|